<template>
  <div v-if="loadingConfig.show" class="loading flex flex-s" :style="style">
    <div class="mask flex flex-s flex-col">
      <template v-if="loadingConfig.type === 'loading'">
        <div class="loading-circle"></div>
        <div class="text-eee mt-12">{{ loadingConfig.text }}</div>
      </template>

      <template v-else-if="loadingConfig.type === 'pay'">
        <div class="text-center">
          <div class="pay-image text-center">
            <img :src="payPng" width="36" />
          </div>
          <div class="text-eee"> 微信支付 </div>

          <div class="loading-dots mt-4">
            <span class="dot"></span>
            <span class="dot"></span>
            <span class="dot"></span>
          </div>
        </div>
      </template>
      <template v-else-if="loadingConfig.type === 'feedback'">
        <div>
          <img :src="checkPng" width="42" />
        </div>
        <div>
          <div class="text-eee"> {{ loadingConfig.text }} </div>
        </div>
      </template>
    </div>
  </div>
</template>

<script setup lang="ts">
  import payPng from '@/views/me/assets/payment.png';
  import { CSSProperties, computed } from 'vue';
  import checkPng from '@/assets/images/check.png';
  import { loadingConfig } from './loading';

  const style = computed((): CSSProperties => {
    return {
      backgroundColor: loadingConfig.value.mask ? 'var(--mask)' : 'transparent',
    };
  });
</script>

<style lang="scss" scoped>
  .loading {
    position: absolute;
    width: 100%;
    height: 100vh;
    z-index: 20;
    top: 0;
    left: 0;
    .mask {
      width: 100px;
      height: 100px;
      background-color: #4b4b4b;
      border-radius: 8px;
    }
    @keyframes spin {
      0% {
        transform: rotate(0deg);
      }
      100% {
        transform: rotate(360deg);
      }
    }

    .loading-circle {
      border: 2px solid #333; /* 边框颜色 */
      border-top: 2px solid #eee; /* 顶部边框颜色 */
      border-radius: 50%;
      width: 40px;
      height: 40px;
      animation: spin 1s linear infinite; /* 动画名称、持续时间、动画类型 */
    }

    .loading-dots {
      text-align: center;
    }
    .pay-image {
      height: 36px;
    }
    .dot {
      display: inline-block;
      width: 6px;
      height: 6px;
      background-color: #fff;
      border-radius: 50%;
      margin: 0 5px;
      animation: blink 1s infinite;
    }
    .dot:nth-child(2) {
      animation-delay: 0.2s;
    }
    .dot:nth-child(3) {
      animation-delay: 0.4s;
    }
    @keyframes blink {
      from {
        opacity: 1;
      }
      to {
        opacity: 0.3;
      }
    }
  }
</style>
